Skip to content

test(document-viewer): shell-state coverage incl. the private-access gate (TCD-03)#1063

Merged
BigSimmo merged 9 commits into
mainfrom
claude/document-viewer-tests-123366
Jul 22, 2026
Merged

test(document-viewer): shell-state coverage incl. the private-access gate (TCD-03)#1063
BigSimmo merged 9 commits into
mainfrom
claude/document-viewer-tests-123366

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds shell-state coverage for DocumentViewer (finding TCD-03). The component resolves a four-way state — loading / ready / auth-required / error — that decides whether a source document is shown at all, and it had no render coverage. Test-only, no product code changes.

The state is prop-drivable via initialDetail / initialError, so the tests pin it without any network:

  • auth-required — a private-access failure resolves to the "Sign in required" shell with its reason, and not to the generic failure shell (which would read as "broken" rather than "sign in"). This is the private-document gate.
  • error — a generic load failure resolves to "Source unavailable" with the reason, and never to the sign-in shell.
  • ready — a supplied detail payload resolves to the document identity and to neither failure shell.

Despite the file's size, only useRouter and useAuthSession are external dependencies (the rest of its hooks are local state), so the harness is small. The next/dynamic PDF preview is mocked defensively so a late resolve cannot pull a real canvas into jsdom.

Note: the assertions are deliberately mutual-exclusivity checks on the resolved shell rather than presence checks on the dynamic preview — the preview never mounts synchronously in jsdom, so asserting on it would have been vacuous.

Verification

  • tests/document-viewer-shell.dom.test.tsx3/3 pass (jsdom)
  • npm run typecheck, npm run lint, npm run format:check clean
  • UI verification not run: no product code or rendered output changes (test-only); the full unit + jsdom suite runs in CI.

Risk and rollout

  • Risk: none. Test-only; adds one jsdom render test file, no product code touched.
  • Rollback: revert this commit.
  • Provider or production effects: None. Verification was fully offline; no provider calls.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added deterministic UI coverage for the Document Viewer’s four shell states: loading/private access sign-in, initial load error (“Source unavailable”), and successful document ready view (including the correct smart-cased title and PDF filename in actions).
    • Ensured the correct messaging renders for each scenario and that unrelated shells do not appear at the same time.

…gate (TCD-03)

DocumentViewer resolves a four-way shell state (loading / ready / auth-required
/ error) that decides whether a source document is shown at all, and it had no
render coverage. The state is prop-drivable via initialDetail / initialError, so
these tests pin it without a network:

- auth-required: a private-access failure resolves to the "Sign in required"
  shell with its reason — not the generic failure shell (which would read as
  "broken" rather than "sign in").
- error: a generic load failure resolves to "Source unavailable" with the
  reason, and never to the sign-in shell.
- ready: a supplied detail payload resolves to the document identity and to
  neither failure shell.

Only useRouter and useAuthSession are external (the rest of the component's
hooks are local state); the next/dynamic PDF preview is mocked defensively so a
late resolve cannot pull a real canvas into jsdom.

Verified: 3/3 pass; typecheck, lint, format:check clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@supabase

supabase Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: de88d0e2-6df9-4064-beff-2edef57fc2f2

📥 Commits

Reviewing files that changed from the base of the PR and between 69c193a and e97b7ea.

📒 Files selected for processing (1)
  • tests/document-viewer-shell.dom.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/document-viewer-shell.dom.test.tsx

📝 Walkthrough

Walkthrough

Adds deterministic DOM coverage for DocumentViewer private-access, error, and ready shells, including document title and PDF filename assertions.

Changes

DocumentViewer shell-state coverage

Layer / File(s) Summary
Shell-state DOM coverage
tests/document-viewer-shell.dom.test.tsx
Mocks navigation, authentication, project identity, and PDF previews; defines a typed document-detail fixture; verifies sign-in, failure, and ready shells with environment and mock cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: codex

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately highlights the new DocumentViewer shell-state coverage and private-access gate.
Description check ✅ Passed The description is detailed and matches the template, but the Clinical Governance Preflight section required for privacy/document-access changes is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/document-viewer-tests-123366

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Unit coverageneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #4345 (success).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/document-viewer-shell.dom.test.tsx`:
- Around line 44-67: Update the detailPayload helper to be validated against the
actual DocumentDetailPayload type, replacing the `as never` assertion with an
explicit return type or a `satisfies DocumentDetailPayload` check while
preserving the existing fixture values.
- Around line 95-99: Update the “shows the ready shell…” test to assert the
supplied document identity directly: verify the rendered title and the exact
filename “clozapine-titration.pdf” from detailPayload(), rather than relying on
the broad /clozapine/i getAllByText match.
- Around line 10-15: Update the navigation mock setup around the hoisted vi.mock
factory to create the push spy via vi.hoisted, ensuring the factory references
the hoisted value instead of the module-scoped const push declaration. Keep the
existing router methods and behavior unchanged.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cd2b9a7d-2256-46fb-9029-0295b1e9b994

📥 Commits

Reviewing files that changed from the base of the PR and between 9273fbe and b73d675.

📒 Files selected for processing (1)
  • tests/document-viewer-shell.dom.test.tsx

Comment thread tests/document-viewer-shell.dom.test.tsx Outdated
Comment thread tests/document-viewer-shell.dom.test.tsx Outdated
Comment thread tests/document-viewer-shell.dom.test.tsx Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b73d675714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/document-viewer-shell.dom.test.tsx
@BigSimmo
BigSimmo enabled auto-merge (squash) July 22, 2026 03:42
…ironment

The auth-required assertion passed on a workstation and failed in CI. The
viewer gates every document request on a local-project identity probe
(/api/local-project-id); when that probe reports no safe local origin it
replaces the viewer error with its own "unsafe local project" message, so
the private-access gate never engages and the sign-in shell never renders.
Whether the probe succeeds depended on a reachable dev server, not on the
behaviour under test.

Stub the probe as a safe local origin, and await the shell text so the
assertion holds whichever tick the state settles on. Flipping the stub to
an unsafe origin reproduces the CI failure exactly, which is the evidence
that this was the cause.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BigSimmo
BigSimmo disabled auto-merge July 22, 2026 03:52
@BigSimmo
BigSimmo enabled auto-merge (squash) July 22, 2026 03:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91d14788ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/document-viewer-shell.dom.test.tsx
In demo / local-no-auth mode every document is public, so the
private-access gate is deliberately inert and the sign-in shell can never
render. The CI runner exports one of those, which turned the gate
assertion into a failure there while it passed on a workstation without
them — reproduced locally with NEXT_PUBLIC_LOCAL_NO_AUTH=true, which
fails exactly the same single test.

Stub both flags off per test so the assertion is about the gate rather
than the runner's mode. Verified green with LOCAL_NO_AUTH=true, with
DEMO_MODE=true, and with a clean environment; flipping the mocked session
to authenticated still turns it red, so the gate is genuinely asserted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BigSimmo
BigSimmo disabled auto-merge July 22, 2026 04:01
@BigSimmo
BigSimmo enabled auto-merge (squash) July 22, 2026 04:01
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 3 unresolved review comments.

Files modified:

  • tests/document-viewer-shell.dom.test.tsx

Commit: f39aaa8f7edc478d72dd147f689c9ab1bc5403fb

The changes have been pushed to the claude/document-viewer-tests-123366 branch.

Time taken: 10m 4s

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 51fbf4bf59

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/document-viewer-shell.dom.test.tsx Outdated
coderabbitai Bot and others added 2 commits July 22, 2026 04:15
Fixed 1 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e97b7eacf8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/document-viewer-shell.dom.test.tsx
@BigSimmo
BigSimmo merged commit 6689529 into main Jul 22, 2026
17 checks passed
@BigSimmo
BigSimmo deleted the claude/document-viewer-tests-123366 branch July 22, 2026 05:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55d820823d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +22 to +25
authorizationHeader: {},
registerAuthRequest: () => ({ epoch: 1, release: vi.fn() }),
isAuthEpochCurrent: () => true,
markSessionExpired: vi.fn(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stabilize the auth mock dependencies

The fresh evidence in this head is that useAuthSession still constructs a new authorizationHeader object and auth callbacks on every render. DocumentViewer includes these values in the document-load effect dependencies, and each initialDetail/initialError load writes fresh array state before rerendering, so this new jsdom suite can keep aborting and restarting the same load path until it times out or hits update-depth/act noise instead of reliably proving the private-document shell. Hoist a single auth session/header/functions object from the mock.

AGENTS.md reference: AGENTS.md:L490-L503

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant